/**
 * 
 */
package model;

import common.DataManager;
import common.GridCoordinate;

import controller.Controller;

/**
 * @author Bill
 *
 */
public class Explosion {
	
	private String image = DataManager.EXPLOSION_1_BY_1;
	private int tickCount = 0;
	private int explosionDuration = (int)(0.1*Controller.ticksPerSecond);		//1/10 second duration (in number of ticks)
	private boolean explosionFinished = false;
	private GridCoordinate pos;
	
	public Explosion(GridCoordinate position, int size){
		this.pos = position;
		switch(size){
		case 1: 
			setImage(DataManager.EXPLOSION_1_BY_1); 
			break;
		case 9: 
			setImage(DataManager.EXPLOSION_3_BY_3); 
			int newPosX = this.pos.getX()-1;
			int newPosY = this.pos.getY()-1;
			this.pos = new GridCoordinate(newPosX, newPosY);
			break;
		case 25: 
			setImage(DataManager.EXPLOSION_5_BY_5); 
			newPosX = this.pos.getX()-2;
			newPosY = this.pos.getY()-2;
			this.pos = new GridCoordinate(newPosX, newPosY);
			break;
		case 150:
			setImage(DataManager.EXPLOSION_ASTEROID);
			this.pos = new GridCoordinate(0,0);
			break;
		default: setImage(DataManager.EXPLOSION_1_BY_1);
		}
	}
	
	public Explosion(GridCoordinate position, int size, float duration){
		this(position,size);
		explosionDuration = (int)(duration*Controller.ticksPerSecond);	
	}
	
	public void incrementTickCount(){
		tickCount++;
		if(tickCount >= explosionDuration) explosionFinished = true;
	}
	
	public boolean explosionFinished(){
		return explosionFinished;
	}

	public GridCoordinate getPosition() {
		return pos;
	}

	public void setPosition(GridCoordinate pos) {
		this.pos = pos;
	}

	public void setImage(String image) {
		this.image = image;
	}

	public String getImage() {
		return image;
	}


}
